//
//  AEUserCommonInfo.swift
//  AESOLAR_IOS
//
//  Created by Bin Tang on 2024/10/12.
//  Copyright © 2024 Mr.Wang. All rights reserved.
//

import UIKit
import RxSwift
import RxCocoa

public class AEUserCommonInfo : NSObject {
    
    /**
     获取当前语言
     */
    @objc static func currentLanguage() -> String {
        return AppCache.shared.object(for: APPUserDefault.self).userSelectLanguage?.header ?? "en"
    }
    
    /**
     是否已经登录
     */
    @objc static func isLogin() -> Bool {
        return APPUser.shared.isLogin;
    }
    
    /**
     得到key
     */
    @objc static func userTypeKey() -> String {
        return APPUser.shared.userInfo.type;
    }
    
    /**
     得到token
     */
    @objc static func getToken() -> String {
        return APPUser.shared.token;
    }
    
    /**
     得到用户id
     */
    @objc static func getUserId() -> String {
        return APPUser.shared.userId;
    }
    
    /**
     退出登录
     */
    @objc static func logout() -> Void {
        APPUser.shared.state = .logOut;
    }
    
    /**
     跳转到登录页面
     */
    @objc static func jumpLoginVC() -> Void {
        let vc = MainNavigationViewController.init(rootViewController: LoginViewController(type: .login))
        UIApplication.shared.keyWindow?.setRootViewController(vc, type: .push)
    }
    
    /**
     分享领积分
     */
    @objc func sharePoints() -> Void {
//        ApiManager.getConfig().request()
//            .map{ $0.jsonDictionary }
//            .map{ $0.dictionaryValue("data").stringValue("apple_store") }
//            .trackingLoading()
//            .subscribe(onNext: { [weak self] (url) in
//                let obj: Any
//                if let diwnloadUrl = URL.init(string: url) {
//                    obj = diwnloadUrl
//                } else {
//                    obj = url
//                }
//                let vc = UIActivityViewController.init(activityItems: [obj], applicationActivities: nil)
//                vc.completionWithItemsHandler = { [weak self] _, success, _, _ in
//                    guard let self = self else { return }
//                    if success {
//                        ApiManager.shareSuccess().request()
//                            .post(.userInfoRefresh)
//                            .subscribe()
//                            .disposed(by: self.rx.disposeBag)
//                    }
//                }
//                self?.present(vc, animated: true , completion: nil)
//            }).disposed(by: rx.disposeBag)
    }
    
}
